Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add jit_compile/1, very basic JIT2 #2424

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

aarroyoc
Copy link
Sponsor Contributor

@aarroyoc aarroyoc commented Jun 17, 2024

I open this PR as I think it's good to have some code merged to not diverge a lot from the master branch.

All the JIT code is under the jit feature which is not enabled by default, so you shouldn't expect any change if you don't enable it (apart from an extra predicate, jit_compile/1, that does nothing).

There are two JITs right now: Only one is in this PR

  • JIT1 was my first attempt. It tries to share all the data structures with the interpreter. I saw some problems with this approach so I stopped it.
  • JIT2 is a new approach, it will manage more things on its own and has a different architecture (heap is shared with the interpreter, but registers and some flags are managed internally). JIT2 still is less capable than JIT1.

I also added a JIT CI test (right now, it fails because JIT1 did support more kinds of predicates).

@UWN
Copy link

UWN commented Jun 18, 2024

Just a naive question: Have you the possibility to abolish a definition (even if it is static)? The systems that do this correctly are rare (like 1, id est SICStus)

@aarroyoc
Copy link
Sponsor Contributor Author

Right now, that's not possible and it is indeed a somewhat difficult problem. Compiled predicates that call other compiled predicates don't check if the later has been abolished. I'll give it some thought

@UWN
Copy link

UWN commented Jun 18, 2024

Within ISO, there is only abolish/1to abolish dynamic predicates. SICStus offers the additional functionality to abolish also static predicates with abolish/2 with option force(true). Being able to abolish static code on a predicate-by-predicate basis is a bit much to ask for since this prevents many optimizations. Maybe the granularity could be somewhat coarser. Like the entire Prolog text that was prepared for execution. Or some dependency mechanism. However, if code is abolished it must be conforming to the logical update semantics...

The most important use case is indeed to reload some code.

@UWN
Copy link

UWN commented Jun 21, 2024

The most important use case is indeed to reload some code.

And the most important current use case of this would indeed be exhaustive testing. Currently, this does not work for asserta/1 & rectact/1and thus the WAM code generation is not much tested either. Even SICStus had (some time ago) issues there.

@aarroyoc aarroyoc changed the title WIP: Add jit_compile/1, very basic JIT1, skeleton of JIT2 WIP: Add jit_compile/1, very basic JIT2 Jul 9, 2024
@aarroyoc aarroyoc marked this pull request as ready for review July 9, 2024 18:59
@aarroyoc
Copy link
Sponsor Contributor Author

aarroyoc commented Jul 9, 2024

I updated the PR, I removed the JIT1, now all the focus is on JIT2, which can only do very basic predicates right now (like a(1,2,3) and query: a(X, Y, Z). But it implements the skeleton of the new architecture, it ships a deref/store implementation in pure CLIF (Cranelift assembly). Everything it's still under a feature flag, so I think it's better to merge it, so code doesn't diverge too much between branches.

@triska
Copy link
Contributor

triska commented Jul 9, 2024

@aarroyoc: Thank you a lot for working on this extremely impressive feature!

In order to merge this with minimal chance for conflicts with other PRs and existing ongoing developments in other branches, do you think it would be good to reduce the changes to exactly those that should actually be kept, by rebasing the PR and removing features that were only present intermittently, if any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants